<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>18_class类的用法</title>
</head>
<body>
  
</body>

<script type="text/javascript">
  // es5造类
  function Person(name, age) {
    this.name = name
    this.age = age
  }
  Person.prototype.sayName = function() {
    return this.name
  }
  let p1 = new Person('zhangsan', 20)
  console.log('es5', p1.sayName())
  console.log('es5', p1);

  // es6造类
  class Person_es6 {
    // 实例化的时候会立即被调用
    constructor(name, age) {
      this.name = name
      this.age = age
    }
    sayName() {
      return this.name
    }
  }
  let p2 = new Person_es6('lisi', 30)
  console.log('es6', p2.sayName())
  console.log('es6', p2)

</script>
</html>